<!DOCTYPE html>
<html lang="en">

<head>

    <!-- Basic -->
    <meta charset="UTF-8"/>

    <title>Table | Nadhif - Responsive Admin Template</title>

    <!-- Mobile Metas -->
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>

    <!-- Import google fonts -->
    <!--<link href="http://fonts.useso.com/css?family=Open+Sans:300,400,600,700,800|Shadows+Into+Light" rel="stylesheet" type="text/css"/>-->

    <!-- Favicon and touch icons -->
    <link rel="shortcut icon" href="__ADMIN__/assets/ico/favicon.ico" type="image/x-icon"/>
    <link rel="apple-touch-icon" href="__ADMIN__/assets/ico/apple-touch-icon.png"/>
    <link rel="apple-touch-icon" sizes="57x57" href="__ADMIN__/assets/ico/apple-touch-icon-57x57.png"/>
    <link rel="apple-touch-icon" sizes="72x72" href="__ADMIN__/assets/ico/apple-touch-icon-72x72.png"/>
    <link rel="apple-touch-icon" sizes="76x76" href="__ADMIN__/assets/ico/apple-touch-icon-76x76.png"/>
    <link rel="apple-touch-icon" sizes="114x114" href="__ADMIN__/assets/ico/apple-touch-icon-114x114.png"/>
    <link rel="apple-touch-icon" sizes="120x120" href="__ADMIN__/assets/ico/apple-touch-icon-120x120.png"/>
    <link rel="apple-touch-icon" sizes="144x144" href="__ADMIN__/assets/ico/apple-touch-icon-144x144.png"/>
    <link rel="apple-touch-icon" sizes="152x152" href="__ADMIN__/assets/ico/apple-touch-icon-152x152.png"/>

    <!-- start: CSS file-->

    <!-- Vendor CSS-->
    <link href="__ADMIN__/assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="__ADMIN__/assets/vendor/skycons/css/skycons.css" rel="stylesheet"/>
    <link href="__ADMIN__/assets/vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet"/>

    <!-- Plugins CSS-->
    <link href="__ADMIN__/assets/plugins/bootkit/css/bootkit.css" rel="stylesheet"/>
    <link href="__ADMIN__/assets/plugins/fullcalendar/css/fullcalendar.css" rel="stylesheet"/>
    <link href="__ADMIN__/assets/plugins/jquery-ui/css/jquery-ui-1.10.4.min.css" rel="stylesheet"/>
    <link href="__ADMIN__/assets/css/toastr.min.css" rel="stylesheet" />
    <!-- Theme CSS -->
    <link href="__ADMIN__/assets/css/jquery.mmenu.css" rel="stylesheet"/>

    <!-- Page CSS -->
    <link href="__ADMIN__/assets/css/style.css" rel="stylesheet"/>
    <link href="__ADMIN__/assets/css/add-ons.min.css" rel="stylesheet"/>

    <!-- end: CSS file-->


    <!-- Head Libs -->
    <script src="__ADMIN__/assets/plugins/modernizr/js/modernizr.js"></script>

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <!--<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>-->
    <!--<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>-->
    <!--<![endif]&ndash;&gt;-->

</head>

<body>

<!-- Start: Header -->
{include file="public/header"}
<!-- End: Header -->

<!-- Start: Content -->
<div class="container-fluid content">

    <div class="row">

        <!-- Sidebar -->
        {include file="public/sidebar"}
        <!-- End Sidebar -->

        <!-- Main Page -->
        <div class="main sidebar-minified">
            <!-- Page Header -->
            <div class="page-header">
                <div class="pull-left">
                    <ol class="breadcrumb visible-sm visible-md visible-lg">
                        <li><a href="{:url('/index')}"><i class="icon fa fa-home"></i>后台主页</a></li>
                        <li><a href="{:url('/informations')}"><i class="icon fa fa-copy"></i>分类管理</a></li>

                    </ol>
                </div>
                <div class="pull-right">
                    <h2>分类列表</h2>
                </div>
            </div>
            <!-- End Page Header -->

            <div class="row">
                <div class="col-lg-12">
                    <div class="panel">
                        <div class="panel-heading bk-bg-primary">
                            <h6><i class="fa fa-copy red"></i><span class="break"></span>分类列表</h6>

                            <div class="panel-actions">
                                <a href="javascript.void(0)" class="btn-setting add-btn" data-target="#addModal" data-toggle="modal"><i class="fa fa-plus"></i></a>
                            </div>
                        </div>
                        <div class="panel-body">
                            <div class="table-responsive">


                                    <table class="table table-striped table-bordered bootstrap-datatable datatable">

                                        <thead>
                                        <tr>
                                            <th style="text-align: center">ID</th>
                                            <th style="text-align: center">栏目名称</th>
                                            <th style="text-align: center">关键字</th>
                                            <th style="text-align: center">操作</th>
                                        </tr>
                                        </thead>

                                        <tbody>
                                        {volist name="cates" id="cate" }

                                        <tr>
                                            <td style="text-align: center;vertical-align: middle;">{$cate['id']}</td>
                                            <td style="text-align: center;vertical-align: middle;">{$cate['catename']}</td>
                                            <td style="text-align: center;vertical-align: middle;">{$cate['ckeywords']}</td>

                                            <td style="text-align: center;vertical-align: middle;">
                                                <button type="button" data-id="{$cate['id']}"
                                                        class="btn  show-btn btn-success " data-target="#showModal" data-toggle="modal" data-id="{$cate['id']}">
                                                    <i class="fa fa-search-plus"></i>
                                                </button>
                                                <button type="button" data-id="{$cate['id']}"
                                                        class="btn edit-btn btn-info " data-target="#editModal" data-toggle="modal" data-id="{$cate['id']}">
                                                    <i class="fa fa-edit"></i>
                                                </button>
                                                <button type="button" data-id="{$cate['id']}"
                                                        class="btn del-btn btn-danger">
                                                    <i class="fa fa-trash-o"></i>
                                                </button>
                                            </td>
                                        </tr>
                                        {/volist}



                                        </tbody>

                                    </table>



                            </div>
                        </div>

                    </div>
                </div>
                <!--分页-->

            </div>


        </div>
        <!-- End Main Page -->

    </div>


    <div class="modal fade" id="showModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <div class="panel-heading bk-bg-primary">
                        <h6  name="show_top"><i class="fa fa-indent red"></i></h6>
                    </div>
                </div>
                <div class="modal-body">
                    <form action="" method="post" enctype="multipart/form-data" class="form-horizontal ">
                        <input type="hidden" name="_method" value="PUT" >
                        <div class="form-group">
                            <label class="col-md-3 control-label ">栏目名称</label>
                            <div class="col-md-9">
                                <input  name="catename" class="form-control"  type="text" disabled >
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-3 control-label" >关键字</label>
                            <div class="col-md-9">
                                <input  name="ckeywords" class="form-control"  type="text" disabled>

                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-md-3 control-label" >描述</label>
                            <div class="col-md-9">
                                <textarea  name="cate_desc" rows="9" class="form-control" disabled ></textarea>
                            </div>
                        </div>


                        <br>
                        <div class="modal-footer" style="text-align: center">

                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <div class="panel-heading bk-bg-primary">
                        <h6 name="edit_top"><i class="fa fa-indent red"></i></h6>
                    </div>
                </div>
                <div class="modal-body">
                    <form id="editForm" action="{:url('/cate')}" method="post" enctype="multipart/form-data" class="form-horizontal ">
                        <input type="hidden" name="_method" value="PUT" >
                        <div class="form-group">
                            <label class="col-md-3 control-label ">栏目名称</label>
                            <div class="col-md-9">
                                <input  name="catename" class="form-control"  type="text"  >
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-3 control-label" >关键字</label>
                            <div class="col-md-9">
                                <input  name="ckeywords" class="form-control"  type="text">

                            </div>
                        </div>


                        <div class="form-group">
                            <label class="col-md-3 control-label" >描述</label>
                            <div class="col-md-9">
                                <textarea  name="cate_desc" rows="9" class="form-control" ></textarea>
                            </div>
                        </div>


                        <br>
                <div class="modal-footer" style="text-align: center">

                    <input type="submit" class="btn-sm btn-primary" value="保存" >

                </div>
                    </form>


                </div>
                </div>
            </div>
        </div>


</div>
</div><!--/container-->
<div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <div class="panel-heading bk-bg-primary">
                    <h6><i class="fa fa-indent red"></i>添加栏目</h6>
                </div>
            </div>
            <div class="modal-body">
                <form action="{:url('/cate')}" method="post" enctype="multipart/form-data" class="form-horizontal ">

                    <div class="form-group">
                        <label class="col-md-3 control-label ">栏目名称</label>
                        <div class="col-md-9">
                            <input  name="catename" class="form-control"  type="text"  >
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-3 control-label" >关键字</label>
                        <div class="col-md-9">
                            <input  name="ckeywords" class="form-control"  type="text">

                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-md-3 control-label" >描述</label>
                        <div class="col-md-9">
                            <textarea  name="cate_desc" rows="9" class="form-control" ></textarea>
                        </div>
                    </div>


                    <br>
                    <div class="modal-footer" style="text-align: center">

                        <input type="submit" class="btn-sm btn-primary" value="保存" >
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<div class="clearfix"></div>


<!-- start: JavaScript-->

<!-- Vendor JS-->
<script src="__ADMIN__/assets/vendor/js/jquery.min.js"></script>
<script src="__ADMIN__/assets/vendor/js/jquery-2.1.1.min.js"></script>
<script src="__ADMIN__/assets/vendor/js/jquery-migrate-1.2.1.min.js"></script>
<script src="__ADMIN__/assets/vendor/bootstrap/js/bootstrap.min.js"></script>
<script src="__ADMIN__/assets/vendor/skycons/js/skycons.js"></script>

<!-- Plugins JS-->
<script src="__ADMIN__/assets/plugins/jquery-ui/js/jquery-ui-1.10.4.min.js"></script>
<script src="__ADMIN__/assets/plugins/moment/js/moment.min.js"></script>
<script src="__ADMIN__/assets/plugins/fullcalendar/js/fullcalendar.min.js"></script>

<!-- Theme JS -->
<script src="__ADMIN__/assets/js/jquery.mmenu.min.js"></script>
<script src="__ADMIN__/assets/js/core.min.js"></script>

<!-- Pages JS -->
<script src="__ADMIN__/assets/js/pages/table.js"></script>

<!-- end: JavaScript-->
<script src="__ADMIN__/assets/js/toastr.min.js"></script>
<script>

    // 设置弹框参数
    toastr.options = {
        closeButton: true,//是否显示关闭按钮
        progressBar: true,//实现显示计时条
        timeOut: "3000",//自动关闭时间
         positionClass: "toast-bottom-left"//提示位置
        // positionClass:"toast-top-full-width" // 顶端，宽度铺满整个屏幕
        // positionClass:" toast-top-right"//  顶端右边
    };


    $(function () {
        //  触发删除用户操作
        $('.del-btn').click(function(){
            // console.log(1111);
            var ac_id = $(this).attr('data-id');

            if (confirm('你确定要 [删除] 吗?')) {
                // 要删除的行
                var obj = $(this).parents('tr');
                // console.log(obj);
                delAjax(ac_id, obj);
            }
        });
        //  触发查询单用户操作
        $('.edit-btn').click(function(){
            var ac_id = $(this).attr('data-id');

            editAjax(ac_id);
        });
        $('.show-btn').click(function(){
            var ac_id = $(this).attr('data-id');
            showAjax(ac_id);
        });

    });

    // 执行删除AJAX
    function delAjax(id, obj){
        $.ajax({
            type: 'delete',
            url : '/cate/'+ id,
            dataType : 'json',
            success:function(data){
                // console.log(data);Object { status: true, id: "27", info: "ID为: 27的用户,删除成功!" }

                if (data.status) {
                    toastr.success(data.info);
                    // 将该tr行删除
                    obj.remove();
                    history.go();
                } else {
                    toastr.error(data.info, '删除失败');
                }

            },
            error :function (){
                alert('AJAX执行失败!!');
            }
        });
    }
    // 执行查询单条AJAX
    function editAjax(id){
        $.ajax({
            type: 'get',
            url : '/cate/'+ id+'/edit',
            dataType : 'json',
            success:function(data){
                console.log(data);
                $('input[name="catename"]').val(data.catename);
                $('h6[name="edit_top"]').html('正在修改'+data.catename);
                $('input[name="ckeywords"]').val(data.ckeywords);
                $('textarea[name="cate_desc"]').val(data.desc);
                // 修改editform的action
                $('form#editForm').attr('action', '/cate/' + id);
            },
            error :function (){
                alert('AJAX执行失败!!');
            }
        });
    }
    function showAjax(id){
        $.ajax({
            type: 'get',
            url : '/cate/'+ id,
            dataType : 'json',
            success:function(data){
                console.log(data);
                $('input[name="catename"]').val(data.catename);
                $('h6[name="show_top"]').html(data.catename+'完整信息');
                $('input[name="ckeywords"]').val(data.ckeywords);
                $('textarea[name="cate_desc"]').val(data.desc);

            },
            error :function (){
                alert('AJAX执行失败!!');
            }
        });
    }

</script>
</body>

</html>